package com.cheer.ba.view.adapter;

import android.view.View;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.cheer.ba.R;
import com.cheer.ba.model.AskGetMoneyModel;
import com.cheer.ba.model.NextLevleModel;
import com.cheer.ba.model.ThreeLevleModel;
import com.cheer.ba.utils.Currency;
import com.cheer.ba.utils.ImageUtils;
import com.cheer.ba.utils.LogUtils;
import com.cheer.ba.utils.Protect;

import java.util.List;

/**
 * Author: hq
 * Email: 834138841@qq.com
 * Comment: //TODO
 * Date: 2017-07-28 14:47
 */
public class ExpandableItemAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {
    private static final String TAG = ExpandableItemAdapter.class.getSimpleName();

    public static final int TYPE_LEVEL_0 = 0;
    public static final int TYPE_LEVEL_1 = 1;
    public static final int TYPE_PERSON = 2;

    public ExpandableItemAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_LEVEL_0, R.layout.item_my_friend_expandable);
        addItemType(TYPE_LEVEL_1, R.layout.item_my_friend_expandable2);
        addItemType(TYPE_PERSON, R.layout.item_my_friend_expandable3);
    }


    @Override
    protected void convert(final BaseViewHolder holder, final MultiItemEntity item) {
        switch (holder.getItemViewType()) {
            case TYPE_LEVEL_0:
//                holder.getView(R.id.id_one_rela).setVisibility(View.VISIBLE);
//                holder.getView(R.id.id_friend_line).setVisibility(View.VISIBLE);
//                holder.getView(R.id.id_two_rela).setVisibility(View.GONE);
//                holder.getView(R.id.id_friend2_line).setVisibility(View.GONE);
//                holder.getView(R.id.id_friend_head3_img).setVisibility(View.GONE);
//                holder.getView(R.id.id_friend3_line).setVisibility(View.GONE);

                final AskGetMoneyModel itemO = (AskGetMoneyModel) item;
                if (itemO.nextLevelCount > 0) {
                    holder.getView(R.id.id_arrow_img).setVisibility(View.VISIBLE);
                    holder.setBackgroundRes(R.id.id_arrow_img, itemO.isExpanded() ? R.drawable.ic_arror_down : R.drawable.ic_arror_normal);
                } else {
                    holder.getView(R.id.id_arrow_img).setVisibility(View.INVISIBLE);
                }
                ImageUtils.showCircleImg(mContext, Protect.setPic(itemO.custImg), R.drawable.ic_user_head, R.drawable.ic_user_head, (ImageView) holder.getView(R.id.id_friend_head_img));
                holder.setText(R.id.id_friend_name_txt, itemO.custNname);
                holder.setText(R.id.id_friend_money_txt, Currency.returnDollar(itemO.money));
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getAdapterPosition();
                        if (itemO.isExpanded()) {
                            collapse(pos);
                        } else {
                            expand(pos);
                        }
                    }
                });
                break;
            case TYPE_LEVEL_1:
//                holder.getView(R.id.id_one_rela).setVisibility(View.INVISIBLE);
//                holder.getView(R.id.id_friend_line).setVisibility(View.GONE);
//                holder.getView(R.id.id_two_rela).setVisibility(View.VISIBLE);
//                holder.getView(R.id.id_friend2_line).setVisibility(View.VISIBLE);
//                holder.getView(R.id.id_friend_head3_img).setVisibility(View.GONE);
//                holder.getView(R.id.id_friend3_line).setVisibility(View.GONE);

                final NextLevleModel item2 = (NextLevleModel) item;
                if (item2.nextLevelCount > 0) {
                    holder.getView(R.id.id_arrow2_img).setVisibility(View.VISIBLE);
                    holder.setBackgroundRes(R.id.id_arrow2_img, item2.isExpanded() ? R.drawable.ic_arror_down : R.drawable.ic_arror_normal);
                } else {
                    holder.getView(R.id.id_arrow2_img).setVisibility(View.INVISIBLE);
                }
                ImageUtils.showCircleImg(mContext, Protect.setPic(item2.custImg), R.drawable.ic_user_head, R.drawable.ic_user_head, (ImageView) holder.getView(R.id.id_friend_head2_img));
                holder.setText(R.id.id_friend_name2_txt, item2.custNname);
                holder.setText(R.id.id_friend_money2_txt, Currency.returnDollar(item2.money));
                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = holder.getAdapterPosition();
                        if (item2.isExpanded()) {
                            collapse(pos, false);
                        } else {
                            expand(pos, false);
                        }
                    }
                });
                break;
            case TYPE_PERSON:
//                holder.getView(R.id.id_one_rela).setVisibility(View.INVISIBLE);
//                holder.getView(R.id.id_friend_line).setVisibility(View.GONE);
//                holder.getView(R.id.id_two_rela).setVisibility(View.INVISIBLE);
//                holder.getView(R.id.id_friend2_line).setVisibility(View.GONE);
//                holder.getView(R.id.id_friend_head3_img).setVisibility(View.VISIBLE);
//                holder.getView(R.id.id_friend3_line).setVisibility(View.VISIBLE);

                final ThreeLevleModel item3 = (ThreeLevleModel) item;
                LogUtils.LogD("啊哈哈", "------------" + item3.custNname + item3.custId);
                ImageUtils.showCircleImg(mContext, Protect.setPic(item3.custImg), R.drawable.ic_user_head, R.drawable.ic_user_head, (ImageView) holder.getView(R.id.id_friend_head3_img));
                holder.setText(R.id.id_friend_name3_txt, item3.custNname);
                holder.setText(R.id.id_friend_money3_txt, Currency.returnDollar(item3.money));
                break;
        }
    }
}